<template>
  <div class="big">
    <p style="text-align: right; margin: 5px 5px 0 0">客服中心</p>
    <p style="margin: 10px 0px 10px 20px; font-size: 26px">您好,</p>
    <p style="margin: 0 0 20px 20px; font-size: 26px">欢迎登录华硕商城</p>

    <div class="bottom">
      <van-form @submit="onSubmit">
        <van-field
          v-model="username"
          name="+86"
          label="+86"
          placeholder="手机号"
          :rules="[{ required: true, message: '请填写手机号' }]"
        />
        <van-field
          v-model="password"
          type="password"
          name="密码"
          label="密码"
          placeholder="密码"
          :rules="[{ required: true, message: '请填写密码' }]"
        />
        <div style="margin: 16px">
          <van-button round block type="info" native-type="submit"
            >立即登录</van-button
          >
        </div>
      </van-form>
      <span style="margin-left: 280px">忘记密码</span>
      <p @click="fun2" style="text-align: center; color: blue;">我先逛逛</p>
    </div>
  </div>
</template>

<script>
// import service from "../../../../utils/service";
import axios from "axios";
let service = axios.create();
import { Dialog } from "vant";
export default {
  data() {
    return {
      username: "",
      password: "",
    };
  },
  methods: {
    fun2(){
      this.$router.push('/homepage').catch(err=>{})
    },
    onSubmit() {
      service({
        url: "http://121.89.205.189:3000/api/user/login",
        method: "post",
        data: {
          loginname: this.username,
          password: this.password,
        },
      }).then((res) => {
        if (res.data.code == 200) {
          Dialog.alert({
            title: "登录",
            message: "登录成功",
          }).then(() => {
            window.sessionStorage.setItem("token", res.data.data.token);
            window.sessionStorage.setItem("userid", res.data.data.user);
            this.$router.push({ path: "/homepage" }).catch((err) => {});
          });
        }
      });
    },
  },
};
</script>

<style scoped>
p {
  color: white;
}
.big {
  background-color: #1e7dff;
}
.van-form {
  margin-top: 30px;
}
.bottom {
  background-color: white;
  overflow: hidden;
  border-radius: 30px 30px 0 0;
  height: 535px;
}
</style>